package com.ls.fw.config.zookeeper.listener;

import org.joda.time.DateTime;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;

import com.ls.fw.config.zookeeper.enums.EventType;
import com.ls.fw.config.zookeeper.event.NodeRefreshEventForServer;
 

public class DefaultZookeeperNodeListenerForServer implements ZookeeperNodeListener, ApplicationEventPublisherAware {
	
	private ApplicationEventPublisher publisher;

	@Override
	public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
		this.publisher = publisher;
	}
    @Override
    public void onZookeeperNodeAdded(Object source, Object event, String eventDesc,String path,String key, String data, DateTime when) {
		this.publisher.publishEvent(new NodeRefreshEventForServer(source, event, eventDesc,path,key, data,EventType.ADDED));
    }

    @Override
    public void onZookeeperNodeUpdated(Object source, Object event, String eventDesc,String path,String key, String data, DateTime when) {
		this.publisher.publishEvent(new NodeRefreshEventForServer(source, event, eventDesc,path,key, data,EventType.UPDATED));
    }

    @Override
    public void onZookeeperNodeDeleted(Object source, Object event, String eventDesc,String path,String key) {
		this.publisher.publishEvent(new NodeRefreshEventForServer(source, event, eventDesc,path,key, null,EventType.REMOVED));
    }
}
